import hashlib
import time
import requests
sess = requests.session()
ip = "192.168.1.231"
def cookie_test():
    data = {"userName":"admin","password":"123456"}
    rp =sess.request("post","http://"+ip+":8080/pinter/bank/api/login",data=data)
    print(rp.text)

    params = {"userName":"admin"}
    rp =sess.request("get","http://"+ip+":8080/pinter/bank/api/query",params=params)
    print(rp.text)

def token_test():
    #1.登录后获得权力
    data = {"userName":"admin","password":"123456"}
    rp =sess.request("post","http://"+ip+":8080/pinter/bank/api/login2",data=data)
    moken = rp.json().get("data")

    #2.鉴定有没有权力
    params = {"userName":"admin"}#鉴权接口中田间一个请求
    headers = {"testfan-token":moken}
    rp =sess.request("get","http://"+ip+":8080/pinter/bank/api/query2",params=params,headers=headers)
    print(rp.text)

def sign_test():
    #生成时间戳
    mytime = int(time.time()*1000)
    #生成签名认证
    mysign = hashlib.md5(("13068017145" + "testfan" + str(mytime)).encode())
    print(mysign.hexdigest())
    json = {"phoneNum":"13068017145","optCode":"testfan","timestamp":mytime,"sign":mysign.hexdigest()}
    rp = sess.request("post", "http://" + ip + ":8080/pinter/com/userInfo", json=json)
    print(rp.text)
if __name__=='__main__':
        cookie_test()
        token_test()
        sign_test()
